var t = getApp();

Component({
    properties: {
        listType: {
            type: Number,
            value: -1,
            observer: function(t, a) {
                this.getData(!0);
            }
        },
        role: {
            type: Number,
            value: 2,
            observer: function(t, a) {
                this.getData(!0);
            }
        },
        province: {
            type: String,
            value: "全国",
            observer: function(t, a) {
                this.getData(!0);
            }
        }
    },
    data: {
        listData: [],
        pageNo: 1,
        total: -1,
        isFirstLoad: !0,
        area: "",
        weddingOrderId: "",
        emptyText: "",
        topNum: 0,
        notSettingCity: !1,
        platform: "ios"
    },
    methods: {
        clickQian: function(t) {
            var a = t.currentTarget.dataset.city, e = t.currentTarget.dataset.weddingorderid;
            this.setData({
                area: a,
                weddingOrderId: e
            }), this.qianDan(!1);
        },
        _clickSetCity: function(t) {
            wx.navigateTo({
                url: "/pages/sendOrder/orderSetting/orderSetting"
            });
        },
        _clickInvite: function(t) {
            var a = t.currentTarget.dataset.detail.weixinProgramShareInfo, e = t.currentTarget.dataset.weddingorderid;
            a.weddingorderid = e, this.triggerEvent("invite", a);
        },
        _clickInviteRule: function(t) {
            wx.navigateTo({
                url: "/pages/sendOrderInvite/sendOrderInvite"
            });
        },
        clickCall: function(t) {
            var a = t.currentTarget.dataset.phone;
            wx.makePhoneCall({
                phoneNumber: a
            });
        },
        refresh: function(t) {
            this.getData(!0);
        },
        lower: function(t) {
            this.getData(!1);
        },
        priceAddCancel: function(t) {
            this.prompt.hideDialog();
        },
        priceAddOk: function(t) {
            this.prompt.hideDialog();
            var a = t.detail;
            this.qianDan(!0, a.marketPrice, a.cooperatePrice);
        },
        doQianSuccess: function() {
            for (var t = this.data.listData, a = 0; a < t.length; a++) {
                var e = t[a];
                if (e.weddingOrderId == this.data.weddingOrderId) {
                    e.qiangDanState = 2, e.qiangDanCount = parseInt(e.qiangDanCount) + 1, t[a] = e;
                    break;
                }
            }
            this.setData({
                listData: t
            });
        },
        qianDan: function(a, e, i) {
            var d, n = this;
            d = 1 == a ? {
                marketPrice: e,
                cooperationPrice: i,
                weddingOrderId: n.data.weddingOrderId
            } : {
                weddingOrderId: n.data.weddingOrderId
            }, t.network.post({
                url: t.url.QiangDanWeddingOrder,
                params: d,
                before: function() {
                    wx.showLoading({
                        title: "正在抢单"
                    });
                },
                success: function(t) {
                    wx.hideLoading();
                    t.data.result;
                    1 == t.data.result ? 1 == t.data.data.openAutoQiangDan ? (wx.showModal({
                        title: "抢单成功",
                        content: "您的资料已提交给对应发单人，对方如有合作意向，将主动与您联系，请您留意。建议开启自动抢单，抢单快人一步",
                        confirmText: "自动抢单",
                        success: function(t) {
                            t.confirm && wx.navigateTo({
                                url: "/pages/sendOrder/orderSetting/orderSetting"
                            });
                        }
                    }), n.doQianSuccess()) : (wx.showModal({
                        title: "抢单成功",
                        content: "您的资料已提交给对应发单人，对方如有合作意向，将主动与您联系，请您留意。",
                        showCancel: !1
                    }), n.doQianSuccess()) : 2 == t.data.result ? wx.showModal({
                        title: "提示",
                        content: t.data.message,
                        showCancel: !1
                    }) : 3 == t.data.result ? n.prompt.showDialog(t.data.data.marketPrice, t.data.data.cooperationPrice) : 4 == t.data.result ? wx.showModal({
                        title: "提示",
                        content: t.data.message,
                        success: function(a) {
                            if (a.confirm) {
                                console.log("data:", t.data.data);
                                var e = t.data.data.type;
                                1 == e ? wx.navigateTo({
                                    url: "/pages/add/addImage/addImage"
                                }) : 2 == e ? wx.navigateTo({
                                    url: "/pages/add/addVideo/addVideo"
                                }) : 3 == e && wx.navigateTo({
                                    url: "/pages/add/addTuwen/addTuwen"
                                });
                            }
                        }
                    }) : wx.showModal({
                        title: "提示",
                        content: t.data.message,
                        showCancel: !1
                    });
                },
                fail: function() {
                    wx.hideLoading(), t.util.showToast("获取数据失败");
                },
                complete: function() {
                    wx.hideNavigationBarLoading();
                }
            });
        },
        getData: function(a) {
            if (a) this.data.pageNo = 1; else if (this.data.total == this.data.listData.length) return;
            var e, i = this;
            0 == this.data.listType ? e = t.url.ListWeddingOrder : 1 == this.data.listType ? e = t.url.ListRecommendWeddingOrder : 2 == this.data.listType && (e = t.url.ListMeQiangDanWeddingOrder), 
            t.network.post({
                url: e,
                params: {
                    pageNo: i.data.pageNo,
                    pageSize: 20,
                    role: i.data.role,
                    province: i.data.province
                },
                before: function() {
                    wx.showNavigationBarLoading(), wx.showLoading({
                        title: "正在加载"
                    });
                },
                success: function(e) {
                    if (wx.hideLoading(), 1 == e.data.result) {
                        var d = [];
                        a || (d = i.data.listData), i.hyAddObjectsFromArray(e.data.data.weddingOrders, d);
                        var n = i.data.pageNo + 1;
                        if (i.setData({
                            total: e.data.data.total,
                            pageNo: n,
                            first: !1,
                            notSettingCity: !1
                        }), a && i.setData({
                            topNum: 0
                        }), 0 == d.length) {
                            var r = "";
                            0 == i.data.listType ? r = "订单空空如也" : 1 == i.data.listType ? r = "暂无订单推荐信息" : 2 == i.data.listType && (r = "暂无抢单信息"), 
                            i.setData({
                                emptyText: r
                            });
                        }
                    } else 2 == e.data.result ? i.setData({
                        notSettingCity: !0,
                        listData: [],
                        total: -1,
                        pageNo: 1
                    }) : t.util.showToast(e.data.message);
                },
                fail: function() {
                    wx.hideLoading(), t.util.showToast("获取数据失败");
                },
                complete: function() {
                    wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
                }
            });
        },
        hyAddObjectsFromArray: function(t, a) {
            for (var e = 0; e < t.length; e++) {
                for (var i = t[e], d = i.orderUserAccessToken + i.role + i.date + i.address, n = !1, r = 0; r < a.length; r++) {
                    var o = a[r];
                    n = d == o.orderUserAccessToken + o.role + o.date + o.address;
                }
                0 == n && a.push(i);
            }
            this.setData({
                listData: a
            });
        }
    },
    ready: function() {
        this.prompt = this.selectComponent("#addPriceDialog");
        var t = this;
        wx.getSystemInfo({
            success: function(a) {
                t.setData({
                    platform: a.platform
                });
            }
        });
    }
});